package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.mapper.OrderDetailMapper;
import com.sky.mapper.OrderMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */

@RestController("AdminOrderController")
@Api(tags = "订单相关接口")
@Slf4j
@RequestMapping("/admin/order")
public class OrderController {



    @Autowired
    private OrderService orderService;

    @ApiOperation("订单搜索接口")
    @GetMapping("/conditionSearch")
    public Result<PageResult<OrderVO>> conditionSearch(OrdersPageQueryDTO pageQueryDTO){
        log.info("分页查询的信息：{}",pageQueryDTO);
        PageResult<OrderVO> orderVOPageResult = orderService.conditionSearch(pageQueryDTO);
        return Result.success(orderVOPageResult);
    }

    @ApiOperation("各个状态的订单数量统计接口")
    @GetMapping("/statistics")
    public  Result<OrderStatisticsVO> getStatistics(){
        return Result.success(orderService.getStatistics());
    }

    @ApiOperation("查询订单详情接口")
    @GetMapping("/details/{id}")
    public  Result<OrderVO>  getOrderDetail(@PathVariable Long id){
        log.info("查询的订单id：{}",id);
        OrderVO orderVO = orderService.getOrderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation("接单接口")
    @PutMapping("/confirm")
    public Result  confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirmOrder(ordersConfirmDTO.getId());
        return Result.success();
    }

    @ApiOperation("拒单接口")
    @PutMapping("/rejection")
    public Result  rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderService.rejection(ordersRejectionDTO.getId(), ordersRejectionDTO.getRejectionReason());
        return Result.success();
    }


    @ApiOperation("取消订单接口")
    @PutMapping("/cancel")
    public Result  cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @ApiOperation("派送订单接口")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }


    @ApiOperation("完成订单接口")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }
}
